package com.cz.modules.jk.controller;

import java.util.Arrays;
import java.util.Map;

import com.cz.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cz.modules.jk.entity.JkCamaraEntity;
import com.cz.modules.jk.service.JkCamaraService;
import com.cz.common.utils.PageUtils;
import com.cz.common.utils.R;



/**
 * 
 *
 * @author Cz
 * @email 
 * @date 2020-04-19 15:38:28
 */
@RestController
@RequestMapping("jk/jkcamara")
public class JkCamaraController {
    @Autowired
    private JkCamaraService jkCamaraService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("jk:jkcamara:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = jkCamaraService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("jk:jkcamara:info")
    public R info(@PathVariable("id") String id){
        JkCamaraEntity jkCamara = jkCamaraService.getById(id);

        return R.ok().put("jkCamara", jkCamara);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("jk:jkcamara:save")
    public R save(@RequestBody JkCamaraEntity jkCamara){
        jkCamaraService.save(jkCamara);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("jk:jkcamara:update")
    public R update(@RequestBody JkCamaraEntity jkCamara){
        ValidatorUtils.validateEntity(jkCamara);
        jkCamaraService.updateById(jkCamara);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("jk:jkcamara:delete")
    public R delete(@RequestBody String[] ids){
        jkCamaraService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 监控相机组织树
     */
    @RequestMapping("/camaraTree")
    public R camaraTree(){
        return R.ok().put("camaraTree",jkCamaraService.camaraTree());
    }
    /**
     * 前端页面indexs中的监控组织树 白图标
     */
    @RequestMapping("/indexsCamaraTree")
    public R indexsCamaraTree(){
        return R.ok().put("indexsTree",jkCamaraService.indexsCamaraTree());
    }

    /**
     * 前端页面indexs中的监控组织树 //黑图标
     */
    @RequestMapping("/indexsCamaraTree1")
    public R indexsCamaraTree1(){
        return R.ok().put("indexsTree",jkCamaraService.indexsCamaraTree1());
    }
    /**
     * 主页南北区监控
     */
    @RequestMapping("/northSouthCamara")
    public R northSouthCamara(){
        return R.ok().put("northCamaraTree",jkCamaraService.northSouthCamara("4")).put("southCamaraTree",jkCamaraService.northSouthCamara("3"));
    }
}
